import { defineStore } from "pinia";
import { ref } from "vue";

export const useCounterStore = defineStore("counter", () => {
    // 数据 （state）
    const count = ref(0);

    // getter (computed)
    const doubleCount = computed(() => count.value * 2);

    // 修改数据的方法 （action）
    const increment = () => {
        count.value++;
    };

    // 异步action
    const loadList = async () => {
        const res = await axios.get(API_URL);
        list.value = res.data.data.channels;
    };

    // 以对象形式返回
    return {
        count,
        doubleCount,
        increment,
        loadList,
    };
});
